$(document).ready(function(){
	$('#block_properties').live('submit', function(){
		form = $(this);
		$.ajax({
			'url': $(this).attr('action'),
			'data': $(this).serialize(),
			'dataType': 'json',
			'beforeSend': function(){
				form.addClass('load');
			},
			'success': function(data){
				form.removeClass('load');

				if($('#block_id').val()){
					$('.block[rel="'+ $('#block_id').val() +'"]').replaceWith(data.block);
				} else {
					$('.field[rel="'+ data.field +'"]').append(data.block);
				}

				$.colorbox.close();
			}
		});
		return false;
	});

	$('#block_action').live('change', function(){
		$('#actionProperties').html("");
		$('#actionProperties').load('?module=pages&action=actionproperties', $('#block_properties').serialize(), function(){
			$.colorbox.resize();
		});
	});
});